package com.sopaths.crawler.conf;

import org.apache.log4j.Logger;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Program {
	private static final Logger logger = Logger.getLogger(Program.class);

	public static void main(String[] args) {
		try {
			logger.info("Start Pitaya Crawler Service.");
			logger.info("Initialize Application Context.");
			//ApplicationContext context =
			new ClassPathXmlApplicationContext(
					"sopaths-crawler.xml",
					"sopaths-crawler-zhilian.xml",
					"sopaths-crawler-51Job.xml");
			logger.info("Initialize Application Context Complete.");
//			CityCrawlerTask task = new CityCrawlerTask();
/*
			task.setSource(CrawlerTaskSource.$ZhiLian);
			task.setType(CrawlerTaskType.CityCrawlerTask);
*/
/*
			task.setSource(CrawlerTaskSource.$51Job);
			task.setType(CrawlerTaskType.CityCrawlerTask);

			CrawlerTaskExecutor executor = context.getBean("cityCrawlerTaskExecutor", CrawlerTaskExecutor.class);
			executor.submit(task);
*/
//			RecruitmentService service = context.getBean(RecruitmentService.class);
//			Recruitment recruitment = new Recruitment();
//			recruitment.setUrl("http://search.51job.com/job/58573946,c.html");
//			service.saveCrawledRecruitment(recruitment);
//			Recruitment recruitment = service.get(0);
//			service.miniCreate();
			try {
				Thread.sleep(Long.MAX_VALUE);
			} catch (InterruptedException ex) {
				logger.error("Main thread has been interrupted.", ex);
				throw new RuntimeException(ex);
			}

		} catch (Exception ex) {
			logger.error("An error occurred while initializing crawler service.", ex);
			throw new RuntimeException(ex);
		}
	}
}
